package hardware;

public class ROBEntry {
	private boolean flag;
	private int value;
	Register logical;
	private String InstructionType;
	private int ID;

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public ROBEntry(Register logic, String type, int Id) {
		logical = logic;
		InstructionType = type;
		flag = false;
		value = 0;
		ID = Id;
	}

	public boolean isFlag() {
		return flag;
	}

	/**
	 * commits certain rob entry.
	 * @return
	 * true if it's ready to be committed.
	 */
	public boolean commit() {
		if (flag) {
			if(!InstructionType.equals(Instruction.BRANCH_IF_EQUAL) 
				&& !InstructionType.equals(Instruction.STORE_WORD)
				&& !InstructionType.equals(Instruction.RETURN)
				&& !InstructionType.equals(Instruction.JUMP)){
			this.logical.value = value;
			}
			return true;
		} else {
			return false;
		}
	}

	public String getIntstructionType() {
		return InstructionType;
	}

	public void setIntstructionType(String intstructionType) {
		InstructionType = intstructionType;
	}

	public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}
	
	public String toString(){
		return " ID: " + ID + " InstructionType: " + InstructionType +  " Ready: " + flag + " Register name: " + logical.getName() + " Value: " + value + "\n" ;
	}

}
